package com.sheepone.util.structure;

/**
 * @author Miss.杨
 * @description
 * @since 2024/5/3 - 20:52
 */
public abstract  class Container {

    public Container() {
        this(Integer.MAX_VALUE);
    }

    public Container(int capacity) {
        if (capacity < 1) {
            throw new IllegalArgumentException("capacity must greater than 0");
        }
        this.capacity = capacity;
    }

    protected int size = 0;

    protected final int capacity;

    public int size() {
        return size;
    }

    public boolean isFull() {
        return size >= capacity;
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean hasSpace(int size) {
        return this.size + size <= capacity;
    }

    public abstract void clear();
}
